package id.game;

import id.utils.Globals;

import java.util.ArrayList;

import org.fenggui.composite.MessageWindow;
import org.fenggui.layout.StaticLayout;

public class Player {

	private String name;
	private Integer money;
	private ArrayList<GameTile> properties;
	
	public Player(String playerName, Integer initialMoney){
		name = playerName;
		money = initialMoney;
		properties = new ArrayList<GameTile>();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getMoney() {
		return money;
	}

	public void setMoney(Integer money) {
		this.money = money;
	}

	public void buyProperty(GameTile prop){
		if(this.money >= prop.getValue()){
			this.money -= prop.getValue();
			this.properties.add(prop);
			String t = "You bought the Property for " + (prop.getValue()) + ".";
			MessageWindow mw = new MessageWindow(t);
			mw.setTitle("Property bought!");
			mw.updateMinSize();
			mw.setSize(mw.getMinWidth() + 100, mw.getMinHeight());
			mw.layout();
			Globals.getDisplay().addWidget(mw);
			StaticLayout.center(mw, Globals.getDisplay());
		} else {
			String t = "You need an extra " + (prop.getValue() - this.money) + " to buy this property.";
			MessageWindow mw = new MessageWindow(t);
			mw.setTitle("Not enough money!");
			mw.updateMinSize();
			mw.setSize(mw.getMinWidth() + 100, mw.getMinHeight());
			mw.layout();
			Globals.getDisplay().addWidget(mw);
			StaticLayout.center(mw, Globals.getDisplay());
		}
	}
	
	public void sellProperty(GameTile prop){
		this.properties.remove(prop);
		this.money += prop.getValue();
		String t = "You sold the property for " + (prop.getValue()) + ".";
		MessageWindow mw = new MessageWindow(t);
		mw.setTitle("Property Sold!");
		mw.updateMinSize();
		mw.setSize(mw.getMinWidth() + 100, mw.getMinHeight());
		mw.layout();
		Globals.getDisplay().addWidget(mw);
		StaticLayout.center(mw, Globals.getDisplay());
	}
	
}
